package cn.fql.basic.service.impl;

import cn.fql.basic.mapper.BaseMapper;
import cn.fql.basic.query.BaseQuery;
import cn.fql.basic.service.IBaseService;
import cn.fql.basic.util.PageList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.update(t);
    }

    @Override
    @Transactional
    public void del(Long id) {
        baseMapper.del(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        Integer count = baseMapper.queryCount(baseQuery);
        if (count ==null){
            return new PageList<T>();
        }
        List<T> list = baseMapper.queryData(baseQuery);
        return new PageList<T>(count,list);
    }

    @Override
    public void patchDel(Long[] ids) {
        baseMapper.patchDel(ids);
    }
}
